package com.xliu.csopenproject.pim_server.image.meta.impl;

import com.xliu.csopenproject.pim_server.image.meta.ImageMetaData;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.Map;

@Mapper
public interface MetaDataTransform {

    MetaDataTransform IMAGE_META_DATA_TRANSFORM = Mappers.getMapper(MetaDataTransform.class);

    @Mapping(target = "width", expression = "java(DropSuffix.INSTANCE.apply(data.get(Constants.IMAGE_WIDTH_NAME)))")
    @Mapping(target = "height", expression = "java(DropSuffix.INSTANCE.apply(data.get(Constants.IMAGE_HEIGHT_NAME)))")
    @Mapping(target = "fileSize", expression = "java(DropSuffix.INSTANCE.apply(data.get(Constants.IMAGE_FILESIZE_NAME)))")
    @Mapping(target = "type", source = Constants.IMAGE_TYPE_NAME)
    @Mapping(target = "longitude", source = Constants.IMAGE_GPS_LONGITUDE_NAME)
    @Mapping(target = "latitude", source = Constants.IMAGE_GPS_LATITUDE_NAME)
    @Mapping(target = "fileName", source = Constants.IMAGE_FILE_NAME)
    @Mapping(target = "date", source = Constants.IMAGE_ORIGIN_TIME)
    ImageMetaData toImageMetaData(Map<String, String> data);
}

